package view.kasse;

import control.SalgsController;
import model.BilletSalg;
import utility.PriceFormater;

/**
 *
 * @author Jeppe
 */
public class KasseBilletListePanel extends javax.swing.JPanel {

    private final KassePanel kassePanel;
    private final BilletSalg billetSalg;

    /**
     * Opretter nyt KasseBilletListePanel
     * @param kassePanel
     * @param billetSalg1
     */
    public KasseBilletListePanel(KassePanel kassePanel, BilletSalg billetSalg1) {
        initComponents();
        this.kassePanel = kassePanel;
        this.billetSalg = billetSalg1;
        setSize(430, 40);
        setLabels();        
    }

    /**
     * Sætter Labels i KasseBilletListePanelet med billetSalgets data
     */
    public void setLabels() {
          vareNavnLabel.setText(billetSalg.getBillet().getBilletType());
        if (SalgsController.getInstance().getAktivtSalg().isValutaDKK()) {
            stykPrisLabel.setText(PriceFormater.formaterPrisTilString(billetSalg.getBillet().getPrisDKK()));
        }else{
            stykPrisLabel.setText(PriceFormater.formaterPrisTilString(billetSalg.getBillet().getPrisEURO()));
        }
        antalLabel.setText(billetSalg.getAntal()+"");
        salgsPrisLabel.setText(PriceFormater.formaterPrisTilString(billetSalg.getSalgsprisMedRabat()));
    }

    /**
     * Metoden sætter rabat på det pågældende BilletSalg
     * @param rabat int
     */
    public void setRabat(int rabat) {
        billetSalg.setRabat(rabat);
        setLabels();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        Rabat = new javax.swing.JMenuItem();
        sletVareMenuItem = new javax.swing.JMenuItem();
        jPanel2 = new javax.swing.JPanel();
        panelKnap = new javax.swing.JButton();
        vareNavnTitelLabel = new javax.swing.JLabel();
        vareNavnLabel = new javax.swing.JLabel();
        stykPrisTitelLabel = new javax.swing.JLabel();
        stykPrisLabel = new javax.swing.JLabel();
        antalTitelLabel = new javax.swing.JLabel();
        antalLabel = new javax.swing.JLabel();
        prisTitelLabel = new javax.swing.JLabel();
        salgsPrisLabel = new javax.swing.JLabel();
        jSeparator7 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();

        Rabat.setText("Tilføj Rabat");
        Rabat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RabatActionPerformed(evt);
            }
        });
        jPopupMenu1.add(Rabat);

        sletVareMenuItem.setText("Fjern denne vare ▓");
        sletVareMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sletVareMenuItemActionPerformed(evt);
            }
        });
        jPopupMenu1.add(sletVareMenuItem);

        setOpaque(false);
        setPreferredSize(new java.awt.Dimension(430, 40));

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(430, 40));

        panelKnap.setContentAreaFilled(false);
        panelKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                panelKnapActionPerformed(evt);
            }
        });

        vareNavnTitelLabel.setText("Varenavn");

        vareNavnLabel.setText("Varenavn");

        stykPrisTitelLabel.setText("Pris/stk.");

        stykPrisLabel.setText("Stykpris");

        antalTitelLabel.setText("Antal");

        antalLabel.setText("Antal");

        prisTitelLabel.setText("Pris");

        salgsPrisLabel.setText("Pris");
        salgsPrisLabel.setVerifyInputWhenFocusTarget(false);

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(vareNavnLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(134, 134, 134)
                .addComponent(prisTitelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(291, 291, 291)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(215, 215, 215)
                .addComponent(stykPrisLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(298, 298, 298)
                .addComponent(antalTitelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(298, 298, 298)
                .addComponent(antalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(vareNavnTitelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(347, 347, 347)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(salgsPrisLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(215, 215, 215)
                .addComponent(stykPrisTitelLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(panelKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(vareNavnLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addComponent(prisTitelLabel))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(stykPrisLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addComponent(antalTitelLabel))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(antalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addComponent(vareNavnTitelLabel))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addComponent(stykPrisTitelLabel))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(salgsPrisLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(panelKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void panelKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_panelKnapActionPerformed
        jPopupMenu1.show(this, getMousePosition().x, getMousePosition().y);
    }//GEN-LAST:event_panelKnapActionPerformed

    private void RabatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RabatActionPerformed
        kassePanel.visRabatPopUpPanel(billetSalg);
    }//GEN-LAST:event_RabatActionPerformed

    private void sletVareMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sletVareMenuItemActionPerformed
        SalgsController.getInstance().fjernBilletFraSalg(billetSalg);
        kassePanel.opdaterKasseListeOgAktivtSalg();
    }//GEN-LAST:event_sletVareMenuItemActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Rabat;
    private javax.swing.JLabel antalLabel;
    private javax.swing.JLabel antalTitelLabel;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JButton panelKnap;
    private javax.swing.JLabel prisTitelLabel;
    private javax.swing.JLabel salgsPrisLabel;
    private javax.swing.JMenuItem sletVareMenuItem;
    private javax.swing.JLabel stykPrisLabel;
    private javax.swing.JLabel stykPrisTitelLabel;
    private javax.swing.JLabel vareNavnLabel;
    private javax.swing.JLabel vareNavnTitelLabel;
    // End of variables declaration//GEN-END:variables
}
